﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace MyImdb.Converters
{
    public class ImdbDateToDateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var dateString = value.ToString();
            if (dateString.Length == 8)
            {
                var year = dateString.Substring(0, 4);
                var month = dateString.Substring(4, 2);
                var date = dateString.Substring(6, 2);

                return string.Format("{0}-{1}-{2}", date, month, year);
            }
            else
            {
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
